﻿(function () {
    'use strict';

    angular
        .module('app.patientdemo')
        .factory('DefaultListsProvider', DefaultListsProvider);

    DefaultListsProvider.$inject = ['$rootScope', '$http'];

    /* @ngInject */
    function DefaultListsProvider($rootScope, $http) {
        var service = {
            GetDefaultLists: GetDefaultLists
            , GetPhysiciansList: GetPhysiciansList
            , GetReferringPhysiciansList: GetReferringPhysiciansList
            , GetPracticesList: GetPracticesList
            , GetDiagnosisList: GetDiagnosisList
            , GetStateList : GetStateList
            , CheckDataLoaded: CheckDataLoaded
        };

        return service;
        /////////////////////
        
        var Physicians;
        var Practices;
        var Diagnosis;
        var States;
        var ReferringPhysicians;
        var ListLoaded = false;


        function GetDefaultLists() {
            return $http.get(apiLocation + 'DefaultLists/' + $rootScope.CurrentLoginID).then(function (response) {
                Physicians = response.data.Physicians;
                Practices = response.data.Practices;
                Diagnosis = response.data.DiagnosisList;
                States = response.data.StateList;
                ReferringPhysicians = response.data.ReferringPhysicians;
                ListLoaded = true;
            });
        }

        function GetPhysiciansList() {
            return Physicians;
        }

        function GetReferringPhysiciansList() {
            return ReferringPhysicians;
        }

        function GetPracticesList() {
            return Practices;
        }

        function GetDiagnosisList() {
            return Diagnosis;
        }

        function GetStateList() {
            return States;
        }

        function CheckDataLoaded() {
            return ListLoaded;
        }
    }
}());
